
<template>
  <div>
    <form @submit.prevent = "fn">
      <label>姓名：</label>
      <input type="text" name = "uname" v-model="form.uname"><br><br>

      <label>年龄：</label>
      <input type="number" name = "age" v-model.number="form.age"><br><br>

      <label>身高：</label>
      <input type="number" step =0.01 name = "height" v-model.number="form.height">(米)<br><br>

      <label>体重：</label>
      <input type="number" step =0.01 name = "weight" v-model.number="form.weight">(公斤)<br><br>

      <label>病史：</label>
      <input type="text" name = "medical" v-model="form.medical"><br><br>

      <button>诊断</button>
    </form>

    <p>患者{{form.uname}}  的诊断结果：{{res}}</p>
  </div>
</template>

<script>
export default {
  data () {
    return {
        form:{
            uname:"",
            age:0,
            height:0,
            weight:0,
            medical:"",
        },
        res:"",
    }
  },
  methods: {
    fn(){
        let height = this.form.height
        let weight = this.form.weight
       
        let bim = weight/(height*height)
        if(bim<=18.4){
            this.res = "体重太轻"
        }else if(bim>=18.5 && bim<24){
            this.res = "体重正常"
        }else if(bim>=24 && bim<28){
            this.res = "体重超重"
        }else if(bim>=28){
            this.res = "肥胖"
        }
    }
  }
}
</script>